package com.website.main.controller;

import com.alibaba.fastjson.JSONObject;
import com.website.main.service.S_User;
import com.website.mybatis.entity.SysUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("admin/user")
public class C_User {

	@Autowired
	S_User userService;

	/**
	 * 获取所有用户
	 * @return
	 */
	@RequestMapping("/getList")
	public String getUserList(String name, @RequestParam(defaultValue = "1")int page,
							  @RequestParam(defaultValue = "-1")int limit){
		return JSONObject.toJSONString(userService.getUserList(name,page,limit));
	}

	/**
	 * 添加用户
	 * @param user
	 */
	@RequestMapping("/save")
	public String saveUser(SysUser user){
		return JSONObject.toJSONString(userService.saveUser(user));
	}
	/**
	 * 修改密码
	 */
	@RequestMapping("/updPWD")
	public String updatePWD(String password){
		return JSONObject.toJSONString(userService.updatePwd(password));
	}
	/**
	 * 重置密码
	 */
	@RequestMapping("/resetPwd")
	public String resetPwd(Integer id){
		return JSONObject.toJSONString(userService.resetPwd(id));
	}
	/**
	 * 删除user数据
	 * @return
	 */
	@RequestMapping("/del")
	public String delUser(@RequestParam Integer id){
		return JSONObject.toJSONString(userService.delUser(id));
	}
	/**
	 * 更新user数据
	 * @return
	 */
	@RequestMapping("/upd")
	public String updUser(SysUser user){
		return JSONObject.toJSONString(userService.updUser(user));
	}
}
